package com.whmall.service.crm.module.invoice.service.impl;

import cn.hutool.core.util.StrUtil;
import com.whmall.service.crm.entity.dto.invoice.SettleCollegeAccountAddReqDTO;
import com.whmall.service.crm.entity.dto.invoice.SettleCollegeAccountQueryReqDTO;
import com.whmall.service.crm.entity.dto.invoice.SettleCollegeAccountUpdateReqDTO;
import org.springframework.stereotype.Component;
import java.io.Serializable;

@Component
public class SettleCollegeAccountValidator implements Serializable {

    private static final long serialVersionUID = 5356626321944474731L;

    /**
     * 针对前端参数 处理
     * @param reqDTO
     */
    public SettleCollegeAccountQueryReqDTO validateQuery(SettleCollegeAccountQueryReqDTO reqDTO) {

        if (StrUtil.isEmpty(reqDTO.getCompanyName())){
            reqDTO.setCompanyName(null);
        }
        return reqDTO;
    }

    public void validateAdd(SettleCollegeAccountAddReqDTO reqDTO) {

        if (reqDTO == null){
            throw new IllegalArgumentException("请求参数异常");
        }

        if (reqDTO.getIsSettled() == null){
            throw new IllegalArgumentException("是否入驻必填");
        }

        if (StrUtil.isEmpty(reqDTO.getCompanyName())){
            throw new IllegalArgumentException("高校或科研机构名称不能为空");
        }

        if (reqDTO.getCustomerImportance() == null){
            throw new IllegalArgumentException("客户重要程度必填");
        }

        if (reqDTO.getIsAcceptElectronicInvoice() == null){
            throw new IllegalArgumentException("是否接受电子发票必填");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginUrl())){
            throw new IllegalArgumentException("登录网址不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginAccount())){
            throw new IllegalArgumentException("登录账号不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginPassword())){
            throw new IllegalArgumentException("登录密码不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getPlatformCompanyName())){
            throw new IllegalArgumentException("平台软件公司不能为空");
        }

        if (reqDTO.getSettleCollegeSettlementMethod() == null){
            throw new IllegalArgumentException("结算方式必填");
        }

    }

    public void validateUpdate(SettleCollegeAccountUpdateReqDTO reqDTO) {

        if (reqDTO == null){
            throw new IllegalArgumentException("请求参数异常");
        }

        if (reqDTO.getId() == null){
            throw new IllegalArgumentException("请求参数ID异常");
        }

        if (reqDTO.getIsSettled() == null){
            throw new IllegalArgumentException("是否入驻必填");
        }

        if (StrUtil.isEmpty(reqDTO.getCompanyName())){
            throw new IllegalArgumentException("高校或科研机构名称不能为空");
        }

        if (reqDTO.getCustomerImportance() == null){
            throw new IllegalArgumentException("客户重要程度必填");
        }

        if (reqDTO.getIsAcceptElectronicInvoice() == null){
            throw new IllegalArgumentException("是否接受电子发票必填");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginUrl())){
            throw new IllegalArgumentException("登录网址不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginAccount())){
            throw new IllegalArgumentException("登录账号不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getLoginPassword())){
            throw new IllegalArgumentException("登录密码不能为空");
        }

        if (StrUtil.isEmpty(reqDTO.getPlatformCompanyName())){
            throw new IllegalArgumentException("平台软件公司不能为空");
        }

        if (reqDTO.getSettleCollegeSettlementMethod() == null){
            throw new IllegalArgumentException("结算方式必填");
        }


    }

}
